Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Xml
Imports System.IO

Public Class ResultsDlg
    Dim _totalParticpants As Integer
    Dim _partipantConnectionDetailsList As List(Of DCHelper.ParticipantConnectionDetails) = Nothing
    Dim _dtSince As DateTime
    Dim _downloadedXmlDoc As XmlDocument = Nothing

    Public Sub New(ByVal totalParticipants As Integer, ByVal dtSince As DateTime, _
            ByVal partipantConnectionDetailsList As List(Of DCHelper.ParticipantConnectionDetails))
        InitializeComponent()
        _totalParticpants = totalParticipants
        _partipantConnectionDetailsList = partipantConnectionDetailsList
        _dtSince = dtSince
    End Sub

    Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        _downloadedXmlDoc = DCHelper.Functions.GetParticipantData(_dtSince, _partipantConnectionDetailsList)

        Dim filterTemplate As String = "{0} or {1} participants\r\nRecords since {2}"
        lblDateRetrieved.Text = DateTime.Now.ToString()
        Dim filterString As String = String.Format(filterTemplate, _partipantConnectionDetailsList.Count, _totalParticpants.ToString(), _dtSince.Date.ToShortDateString())
        lblFilters.Text = filterString

        'Save the results to a temp file and point the
        'web browser control to that so that it displays xml
        'neatly formatted 

        Dim tempFile As String = System.IO.Path.GetTempFileName()
        tempFile += ".xml"
        _downloadedXmlDoc.Save(tempFile)
        webBrowserResults.Navigate(tempFile)
    End Sub

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
        Dim saveFileDlg As New SaveFileDialog()
        saveFileDlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"
        saveFileDlg.FilterIndex = 1
        saveFileDlg.RestoreDirectory = True

        If saveFileDlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            _downloadedXmlDoc.Save(saveFileDlg.FileName)
        End If
    End Sub

    Private Sub btnClose_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
End Class